<template>
	<view class="container">
		<view class="dataList">
			<view class="filter" style="">
				<view>
					<view class="filter-item" @click="onDistanceShow">
						<text v-if="!distance_name">全部</text>
						<text v-if="distance_name">{{distance_name}}</text>
						<image src="../../static/images/arrow-bottom.png" mode=""></image>
					</view>
					<view class="filter-item" @click="onTypeShow">
						<text v-if="!type_name">类型</text>
						<text v-if="type_name">{{type_name}}</text>
						<image src="../../static/images/arrow-bottom.png" mode=""></image>
					</view>
					<view class="filter-item" @click="onOrderShow">
						<text v-if="!order_name">按距离排序</text>
						<text v-if="order_name">{{order_name}}</text>
						<image src="../../static/images/arrow-bottom.png" mode=""></image>
					</view>
				</view>
			</view>

			<view v-show="distanceShow" class="tui-dropdownlist" style="">
				<view class="tui-dropdownlist-item tui-icon-middle" style="margin-bottom: 20rpx;">
					<text @click="doDistance(0,0,'全部')" class="tui-ml tui-middle">全部</text>
					<text @click="doDistance(0,100,'100km以下')" class="tui-ml tui-middle">100km以下</text>
					<text @click="doDistance(100,500,'100-500km')" class="tui-ml tui-middle">100-500km</text>
					<text @click="doDistance(500,1000,'500-1000km')" class="tui-ml tui-middle">500-1000km</text>
					<text @click="doDistance(1000,0,'1000km以上')" class="tui-ml tui-middle">1000km以上</text>
				</view>
			</view>
			<view v-show="typeShow" class="tui-dropdownlist" style="">
				<view class="tui-dropdownlist-item tui-icon-middle" style="margin-bottom: 20rpx;">
					<text @click="doCategory('','')" class="tui-ml tui-middle">全部</text>
					<text @click="doCategory(item.id,item.title)" class="tui-ml tui-middle"
						v-for="item in category">{{item.title}}</text>
				</view>
			</view>
			<view v-show="orderShow" class="tui-dropdownlist" style="">
				<view class="tui-dropdownlist-item tui-icon-middle" style="margin-bottom: 20rpx;">
					<text @click="doOrder('distance','按距离排序')" class="tui-ml tui-middle">按距离排序</text>
					<text @click="doOrder('id','最新师傅')" class="tui-ml tui-middle">最新师傅</text>
				</view>
			</view>

			<view style="height: 140rpx;"></view>
			<view :class="'list acea-row row-between-wrapper ' + (is_switch==true?'':'on')">
				<navigator v-for="(item, index) in dataList" :key="index" :class="'item ' + (is_switch==true?'':'on')"
					hover-class="none" :url="'/pages/technical/details?id=' + item.id">
					<view :class="'pictrue ' + (is_switch==true?'':'on')">
						<image :src="item.touxiang || '/static/images/my/mine_def_touxiang_3x.png'"
							:class="is_switch==true?'':'on'" mode="aspectFill"></image>
					</view>
					<view :class="'text ' + (is_switch==true?'':'on')">
						<view class="name line1">{{item.title}}
							<text v-if="item.distance" class="kmclass">[{{item.distance}}km]</text>
						</view>
						<view class="star">
							<image src="/static/images/star_32px.png"></image>
							<image src="/static/images/star_32px.png"></image>
							<image src="/static/images/star_32px.png"></image>
							<image src="/static/images/star_32px.png"></image>
							<image src="/static/images/star_32px.png"></image>
						</view>
						<view class="address">
							<image src="/static/images/address.png"
								style="margin-right: 10rpx;vertical-align: middle;width:30rpx; height: 30rpx;"></image>
							<block v-if="item.region_name">{{item.region_name}}</block>{{item.dizhi || ''}}
						</view>
					</view>
				</navigator>
				<view class="loadingicon acea-row row-center-wrapper" v-if="dataList.length > 0">
					<text class="loading iconfont icon-jiazai" :hidden="loading==false"></text>
				</view>
			</view>
		</view>
		<view class="noCommodity" v-if="dataList.length==0 && where.page > 1">
			<view class="pictrue">

			</view>
		</view>
		<tui-tabbar :current="current">
		</tui-tabbar>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				orderShow: false,
				distance_name: '',
				order_name: '',
				type_name: '',
				distanceShow: false,
				typeShow: false,
				current: '',
				category: [],
				dataList: [],
				navH: "",
				is_switch: false,
				where: {
					order: '',
					keyword: '',
					priceOrder: '',
					salesOrder: '',
					min_distance: 0,
					max_distance: 0,
					news: 0,
					page: 1,
					limit: 10,
					cid: 0,
					latitude: "",
					longitude: ""
				},
				price: 0,
				stock: 0,
				nows: false,
				loadend: false,
				loading: false,
				bottommenulist: [],
				inputShowed: "",
				host_product: "",
				title: "",
				position: "",
				latitude: "",
				longitude: "",
				cid: ""
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			const _this = this; //位置授权
			this.where.cid = options.cid || ''
			this.current = "/" + this.__route__;

			// #ifdef MP-TOUTIAO
			uni.getLocation({
				type: 'wgs84',
				success(res) {
					_this.position = res.address;
					_this.where.latitude = res.latitude;
					_this.where.longitude = res.longitude;
					_this.loadend = false;
			
					_this.title = options.title || '';
					_this.where.keyword = options.searchValue || '';
					_this.inputShowed = options.inputShowed || '';
			
					if (!options.inputShowed) {
						_this.get_technical_list();
					}
				}
			});
			// #endif
			
			// #ifdef MP-WEIXIN
			wx.authorize({
				scope: 'scope.userFuzzyLocation',
				success: res => {
					//console.log(res)
					wx.getFuzzyLocation({
						type: 'wgs84',
						success(res) {
							_this.position = res.address;
							_this.where.latitude = res.latitude;
							_this.where.longitude = res.longitude;
							_this.loadend = false;
			
							_this.title = options.title || '';
							_this.where.keyword = options.searchValue || '';
							_this.inputShowed = options.inputShowed || '';
			
							if (!options.inputShowed) {
								_this.get_technical_list();
							}
			
						}
					});
				},
				fail: res => {
					//console.log('失败：', res);
				}
			});
			// #endif
			
			this.get_cate_list();
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {

			this.where.page = 1;
			this.loadend = false;
			this.dataList = [];
			this.get_technical_list();
			uni.stopPullDownRefresh();
		},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			this.get_technical_list();
		},
		methods: {
			onBoxClose() {
				this.typeShow = false;
				this.distanceShow = false;
				this.orderShow = false;
			},
			onTypeShow() {
				var state = true
				if (this.typeShow == true) {
					state = false
				}
				this.onBoxClose();
				this.typeShow = state
			},
			onOrderShow() {
				var state = true
				if (this.orderShow == true) {
					state = false
				}
				this.onBoxClose();
				this.orderShow = state;
			},
			onDistanceShow() {
				var state = true
				if (this.distanceShow == true) {
					state = false
				}
				this.onBoxClose();
				this.distanceShow = state;
			},
			doCategory: function(cid, name) {
				this.type_name = name
				this.where.cid = cid;
				this.loadend = false;
				this.where.page = 1;
				this.onBoxClose();
				this.get_technical_list(true);
			},
			doOrder: function(order, name) {
				this.order_name = name
				this.where.order = order;
				this.loadend = false;
				this.where.page = 1;
				this.onBoxClose();
				this.get_technical_list(true);
			},
			doDistance: function(min, max, name) {
				this.distance_name = name
				this.where.min_distance = min;
				this.where.max_distance = max;
				this.loadend = false;
				this.where.page = 1;
				this.onBoxClose();
				this.get_technical_list(true);
			},
			get_cate_list: function() {
				var that = this;
				that.$request.get('category.list', {
					ptype: 2
				}).then(res => {
					that.category = res.data;
				});
			},
			//查找店铺
			get_technical_list: function(isPage) {
				var that = this;
				if (that.loadend) return;
				if (that.loading) return;
				if (isPage === true) {
					that.dataList = [];
				}
				that.$request.post('technical.list', that.where).then(res => {
					var dataList = res.data.data;
					var loadend = dataList.length < that.where.limit;
					that.where.page = that.where.page + 1;
					that.loadend = loadend;
					that.loading = false;
					that.dataList = dataList;
				});
			}
		}
	};
</script>
<style>
	.tui-searchbox {
		width: 100%;
		height: 92rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 100;
	}

	.tui-searchbox::after {
		content: '';
		position: absolute;
		border-bottom: 1rpx solid #d2d2d2;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		bottom: 0;
		right: 0;
		left: 0;
	}

	.tui-search-input {
		width: 100%;
		height: 60rpx;

		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-search-input>input {
		flex: 1;
		padding: 10rpx 20rpx;
		background: #f1f1f1;
		font-size: 26rpx;
		color: #999;
		border-radius: 30rpx;
	}

	.tui-search-text {
		padding-left: 16rpx;
	}

	page {
		font-size: 28rpx;
		background-color: #f5f5f5;
		color: #333;
	}

	.container {
		padding-bottom: 228rpx;
		color: #333;
	}

	.dataList .search {
		width: 100%;
		height: 86rpx;
		padding-left: 23rpx;
		box-sizing: border-box;
		position: fixed;
		display: flex;
		left: 0;
	}

	.dataList .bg-color {
		background-color: #e41f19;
	}

	.dataList .search .location {
		color: #fff;
		flex: 1;
		display: flex;
		width: 62rpx;
		font-size: 40rpx;
		height: 86rpx;
		line-height: 86rpx;
		background-image: '../../images/location_fill.png'
	}

	.dataList .search .input {
		flex: 1;
		display: flex;
		width: 570rpx;
		height: 60rpx;
		background-color: #fff;
		border-radius: 50rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
	}

	.dataList .search .input input {
		width: 478rpx;
		height: 100%;
		font-size: 26rpx;
	}

	.dataList .search .input .placeholder {
		color: #999;
	}

	.dataList .search .input .iconfont {
		font-size: 35rpx;
		color: #555;
	}

	.dataList .search .icon-pailie,
	.dataList .search .icon-tupianpailie {
		color: #fff;
		width: 62rpx;
		font-size: 40rpx;
		height: 86rpx;
		line-height: 86rpx;
	}

	.navscroll {
		height: 86rpx;
		position: fixed;
		display: flex;
		white-space: nowrap;
		top: 88rpx;
	}

	.dataList .nav {
		width: 1000rpx;
		display: flex;
		color: #454545;
		font-size: 28rpx;
		background-color: #fff;
	}

	.dataList .nav .item {
		text-align: center;
		height: 100%;
		padding: 25rpx;
	}

	.dataList .nav .item.font-color {
		font-weight: bold;
	}

	.dataList .nav .item image {
		width: 15rpx;
		height: 19rpx;
		margin-left: 10rpx;
	}

	.dataList .list {
		padding: 0 20rpx;
		/* padding-top: 80rpx; */
		margin-top: 6rpx;
	}

	.kmclass {
		color: #999;
	}

	.dataList .list.on {
		/* background-color: #fff;
		border-top: 1px solid #f6f6f6; */
	}

	.dataList .list .item {
		width: 100%;
		margin-bottom: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;
		box-sizing: border-box;
	}

	.dataList .list .item.on {
		width: 100%;
		display: flex;
		/* border-bottom: 1rpx solid #f6f6f6; */
		padding: 30rpx;
		/* margin: 0; */
	}

	.dataList .list .item .pictrue {
		width: 100%;
		height: 345rpx;
	}

	.dataList .list .item .pictrue.on {
		width: 150rpx;
		height: 150rpx;
	}

	.dataList .list .item .pictrue image {
		width: 150rpx;
		height: 150rpx;
		border-radius: 10rpx 10rpx 0 0;
	}

	.dataList .list .item .pictrue image.on {
		border-radius: 6rpx;
	}

	.dataList .list .item .text {
		padding: 20rpx 17rpx 26rpx 17rpx;
		font-size: 28rpx;
		color: #373333;
	}

	.dataList .list .item .text.on {
		width: 508rpx;
		padding: 0 0 0 22rpx;
	}

	.dataList .list .item .text .money {
		font-size: 23rpx;
		margin-top: 8rpx;
	}

	.dataList .list .item .text .money.on {
		margin-top: 50rpx;
	}

	.dataList .list .item .text .money .num {
		font-size: 32rpx;
	}

	.dataList .list .item .text .vip {
		font-size: 22rpx;
		color: #aaa;
		margin-top: 7rpx;
	}

	.dataList .list .item .text .vip.on {
		margin-top: 12rpx;
	}

	.dataList .list .item .text .vip .vip-money {
		font-size: 24rpx;
		color: #282828;
		font-weight: bold;
	}

	.dataList .list .item .text .vip .vip-money image {
		width: 46rpx;
		height: 21rpx;
		margin-left: 4rpx;
	}

	.noCommodity {
		background-color: #fff;
	}

	.star {
		margin-top: 10rpx;
	}

	.star image {
		width: 28rpx;
		height: 28rpx;
	}

	.filter {
		position: fixed;
		top: 0rpx;
		line-height: 120rpx;
		width: 100%;
		background: #fff;
	}

	.filter>view {
		display: flex;
		align-items: center;
	}

	.filter-item {
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
	}

	.filter-item>image {
		width: 32rpx;
		height: 32rpx;
		padding-left: 10rpx;
	}

	.tui-dropdownlist {
		position: fixed;
		left: 0;
		top: 120rpx;
		z-index: 999;
		background: #fff;
		width: 100%;
	}

	.tui-middle {
		display: block;
		padding: 20rpx 20rpx;
		border-bottom: 2rpx solid #f2f2f2;
		font-size: 32rpx;
	}
</style>